package code290;

import java.util.HashMap;
import java.util.Map;

public class Code290 {
    public boolean wordPattern(String pattern, String s) {
        char[] ch = pattern.toCharArray();
        String[] arr = s.split(" ");
        Map<Character,String> map = new HashMap<>();
        if (ch.length!=arr.length)
            return false;
        for (int i=0;i<ch.length;i++) {
            if (map.get(ch[i])!=null){
                if (map.get(ch[i]).equals(arr[i]))
                    continue;
                return false;
            }else {
                if(map.containsValue(arr[i]))
                    return false;
                map.put(ch[i],arr[i]);
            }
        }
        return true;
    }

}
